﻿using MetroDataApi.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace MetroDataApi.Controllers
{
    public class AllProjectsController : ApiController
    {
        // GET api/allprojects
        public string Get()
        {
            using (var db = new MetroDataDataContext())
            {
                var list = from p in db.Projects
                           join q in db.MonitorProjectExtraInfo
                           on p.PrjId equals q.PrjId
                           into gs
                           from g in gs.DefaultIfEmpty()
                           orderby p.LineId
                           select new
                           {
                               PrjId = p.PrjId,
                               Name = p.Name,
                               LineId = p.LineId,
                               LineName = db.Lines.SingleOrDefault(t => t.Id == p.LineId).Name,
                               Remark = p.Remark,
                               Status = p.Status,
                               Location = p.Location,
                               PrjSummary = g != null ? g.PrjSummary : null,
                               PrjLevel = g != null ? g.PrjLevel : "特级",
                               TunnelType = g != null ? g.TunnelType : "单圆隧道",
                               ConstructionCorp = g != null ? g.ConstructionCorp : "上勘院",
                               PrjState = g != null ? g.PrjState : "开挖"
                           };
                string ignored = JsonConvert.SerializeObject(list);
                return ignored;
            }
        }
    }
}
